package zzc.javaWeb.javaWebHomew.control;


import zzc.javaWeb.javaWebHomew.servlet.loginServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/loginR")
public class AdminLoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid = req.getParameter("id");
        String spas = req.getParameter("password");
        System.out.println(sid);
        //拿到servlet层的对象
        loginServlet loginser = new loginServlet();
        //通过loginser对象来拿到服务层的数据，通过flag收取然后在control层操作
        int flag = 0;
        try {
            flag = loginser.getLogin(sid,spas);
            if (flag==1){
                //登陆成功
                System.out.println("登录成功");
                //重定向
                resp.sendRedirect("/Jer/home.jsp");
            }else if (flag==0){
                System.out.println("登录失败");
                resp.sendRedirect("/Jer/adminLoginerr.html");
            }else{
                System.out.println("error");
                resp.sendRedirect("/Jer/adminLogin.html");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
